/* ************************************************************************
> File Name:     bagweight-01.cpp
> Author:        程序员lyl
> 微信公众号:    雨特宙
> Created Time:  2024年03月23日 星期六 16时45分20秒
> Description:   
 ************************************************************************/
#include<iostream>
#include<vector>
using namespace std;

int n, bagweight;
void solve(){

    vector<int> weight(n,0);
    vector<int> value(n,0);
    for(int i = 0; i <n; ++i){
        cin >> weight[i];
    }
    for(int j = 0; j < n; j++){

        cin >> value[j];
    }
    vector<vector<int>> dp(weight.size(), vector<int>(bagweight + 1, 0));

    for(int j = weight[0]; j <= bagweight; j++){
        dp[0][j] = value[0];
    }
    for(int i = 1; i < weight.size(); i++){
        for(int j = 0; j <= bagweight; j++){
            if(j < weight[i]) dp[i][j] = dp[i-1][j];
            else dp[i][j] = max(dp[i-1][j], dp[i-1][j-weight[i]] + value[i]);
        }
    }
    cout<< dp[weight.size() - 1][bagweight] << endl;
}


int main(){
    while(cin >> n >> bagweight){
        solve();
    }
    return 0;
}
